package top.sdwu_top.kbase.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.google.common.collect.Lists;
import top.sdwu_top.kbase.entity.KbaseAuthUser;
import top.sdwu_top.kbase.entity.KbaseFileShare;
import top.sdwu_top.kbase.mapper.KbaseFileShareMapper;
import top.sdwu_top.kbase.service.IKbaseFileShareService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * 文件分享表  服务实现类
 * </p>
 *
 * @author zhipeng.duan@nvr-china.com
 * @since 2020-03-10
 */
@Service
public class KbaseFileShareServiceImpl extends ServiceImpl<KbaseFileShareMapper, KbaseFileShare> implements IKbaseFileShareService {

    @Override
    public List<String> getSharedFileList(KbaseAuthUser user) {
        QueryWrapper<KbaseFileShare> qw = Wrappers.query();
        qw.eq("USER_ID", user.getId());
        List<KbaseFileShare> fileShareList = super.list(qw);
        if (CollectionUtils.isEmpty(fileShareList)) {
            return Lists.newArrayListWithExpectedSize(0);
        }
        return fileShareList.parallelStream().map(KbaseFileShare::getFileId).collect(Collectors.toList());
    }
}
